<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------

// 应用公共文件

function authTopList(){
	$where["id"] = ["gt",0];
    $where["parent_id"] = 0;
    $ad_auth = db('ad_auth')->where($where)->select();
    $list = [];
    foreach ($ad_auth as $key => $value) {
    	$list[$value["id"]] = $value["name"];
    }
    return $list;
}

function authList($parent_id){
    $where1["id"] = ["gt",0];
    $where1["parent_id"] = $parent_id;
    $ad_auth = db('ad_auth')->where($where1)->select();
    return $ad_auth;
}

function getAllAuth(){
    $array = authList(0);
    $list = [];
    foreach ($array as $key => $value) {
        $list[] = $value;
        $cache = authList($value["id"]);
        $list = array_merge($list,$cache);
    }
    return $list;
}

function authAllList($parent_id = 0){
    $ad_auth = authList($parent_id);

    foreach ($ad_auth as $key => $value) {
	    $ad_auth[$key]["children"] = authList($value["id"]);
    }

    return $ad_auth;
}
